package com.group9.service.impl;

import com.group9.mapper.AdminMapper;
import com.group9.pojo.Admin;
import com.group9.pojo.AdminExample;
import com.group9.service.LoginService;
import com.group9.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by Lcouncillor on 2020/4/10.
 */
public class LoginServiceImpl implements LoginService {
    AdminMapper adminMapper = null;
    public Admin adLogin(String adminName, String adminPwd) {
        SqlSession sqlSession = SqlSessionUtil.openSqlSession();
        adminMapper = sqlSession.getMapper(AdminMapper.class);

        AdminExample adminExample = new AdminExample();
        AdminExample.Criteria criteria = adminExample.createCriteria();
        criteria.andAdminNameEqualTo(adminName);
        criteria.andAdminPwdEqualTo(adminPwd);
        List<Admin> admin = adminMapper.selectByExample(adminExample);

        if ( null != admin && !admin.isEmpty()){
            return admin.get(0);
        }

        sqlSession.close();
        return null;
    }
}
